package br.com.werp.suporte.Geral;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.egen.util.jdbc.*;
import com.egen.util.text.*;

/**
 * Creation Date 06/11/2006 09:50:58
 * Last Modify Date 09/11/2006 11:47:10
 */

public class PesquisaNaturalidadeAction extends com.egen.util.struts.AbstractAction {

  public ActionForward perform_pesquisar_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //------------------------------------------------------------------------
      br.com.werp.regras.geral. GerenciamentoEndereco gerenciamentoEndereco =
        br.com.werp.regras.geral.FabricaSubSistema. getGerenciamentoEndereco();

      session.setAttribute("naturalidades",
          gerenciamentoEndereco.pesquisarCidade(form));
      //------------------------------------------------------------------------
      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              (e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          (e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

  public ActionForward perform_resetfull_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //----------------------------------------------------------------------------
      session.setAttribute("naturalidades",new ArrayList());
      form.reset(null, null);
      //----------------------------------------------------------------------------

      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              (e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          (e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

  public ActionForward perform_popup_action(ActionMapping mapping,
      ActionForm form, HttpServletRequest request,
      HttpServletResponse response) {
    HttpSession session = request.getSession(true);
    ActionForward actionForward = null;
    try {
      //------------------------------------------------------------------

      String usur_login = request.getParameter("usur_login");
      if (usur_login != null && !"".equals(usur_login)) {
        session.setAttribute("j_username",usur_login);
      }

      session.setAttribute("naturalidades",new ArrayList());
      session.setAttribute("return0",request.getParameter("return0"));
      session.setAttribute("return1",request.getParameter("return1"));
      //------------------------------------------------------------------

      actionForward = mapping.findForward("same");
    } catch (Exception e) {
      ActionErrors errors = new ActionErrors();
      errors.add("ActionErrors.GLOBAL_ERROR",
          new ActionError("error.action.exception",
              (e)));
      request.setAttribute(org.apache.struts.Globals.ERROR_KEY, errors);
      session.setAttribute("exception",
          (e));
      actionForward = mapping.findForward("same");
    }
    return actionForward;
  }

}
